use std::sync::Arc;

use valuation_model::{node::Node, schema::Schema};

pub trait Step {
    fn apply(&self, doc: Arc<Node>, schema: Arc<Schema>) -> StepResult;
    fn to_json(&self) -> serde_json::Value;
}

pub struct StepResult {
    pub doc: Option<Arc<Node>>,
    pub failed: Option<String>,
}

impl StepResult {
    pub fn ok(doc: Arc<Node>) -> Self {
        StepResult {
            doc: Some(doc),
            failed: None,
        }
    }

    pub fn fail(message: String) -> Self {
        StepResult {
            doc: None,
            failed: Some(message),
        }
    }
}
